﻿<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="../../../assets/docs.css" rel="stylesheet" type="text/css" media="screen" />
<title>MooTools Documentation - Types/Array</title>
</head>

<body>
  <div id="docs" class="doc">
    <div class="methods">
      <h4 class="menu-item"><a href="#Array">Array</a></h4>
      <div class="menu-item"><a href="#Array:Array-each">Array.each</a></div>
      <div class="menu-item"><a href="#Array:Array-clone">Array.clone</a></div>
      <div class="menu-item"><a href="#Array:Array-from">Array.from</a></div>
      <div class="menu-item"><a href="#Array:each">each</a></div>
      <div class="menu-item"><a href="#Array:invoke">invoke</a></div>
      <div class="menu-item"><a href="#Array:every">every</a></div>
      <div class="menu-item"><a href="#Array:filter">filter</a></div>
      <div class="menu-item"><a href="#Array:clean">clean</a></div>
      <div class="menu-item"><a href="#Array:indexOf">indexOf</a></div>
      <div class="menu-item"><a href="#Array:map">map</a></div>
      <div class="menu-item"><a href="#Array:some">some</a></div>
      <div class="menu-item"><a href="#Array:associate">associate</a></div>
      <div class="menu-item"><a href="#Array:link">link</a></div>
      <div class="menu-item"><a href="#Array:contains">contains</a></div>
      <div class="menu-item"><a href="#Array:append">append</a></div>
      <div class="menu-item"><a href="#Array:getLast">getLast</a></div>
      <div class="menu-item"><a href="#Array:getRandom">getRandom</a></div>
      <div class="menu-item"><a href="#Array:include">include</a></div>
      <div class="menu-item"><a href="#Array:combine">combine</a></div>
      <div class="menu-item"><a href="#Array:erase">erase</a></div>
      <div class="menu-item"><a href="#Array:empty">empty</a></div>
      <div class="menu-item"><a href="#Array:flatten">flatten</a></div>
      <div class="menu-item"><a href="#Array:pick">pick</a></div>
      <div class="menu-item"><a href="#Array:hexToRgb">hexToRgb</a></div>
      <div class="menu-item"><a href="#Array:rgbToHex">rgbToHex</a></div>
    </div>
    <div class="l-border r-border span-15 content">
				<h1 id="Array"><a href="#Array">Type: Array</a></h1>

<p class="description">A collection of Array methods and functions.</p>

<h3>See Also:</h3>

<ul>
<li><a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array">MDC Array</a></li>
</ul>
<h2 id="Array:Array-each"><a href="#Array:Array-each">Function: Array.each</a></h2>

<p class="description">Used to iterate through arrays, or iterables that are not regular arrays, such as built in getElementsByTagName calls or arguments of a function.</p>

<h3>Syntax:</h3>

<pre class="javascript">Array.<span class="me1">each</span><span class="br0">(</span>iterable, fn<span class="br0">[</span>, bind<span class="br0">]</span><span class="br0">)</span>;
</pre>

<h3>Arguments:</h3>

<ol>
<li>iterable - (<em>array</em>) The array to iterate through.</li>
<li>fn       - (<em>function</em>) The function to test for each element.</li>
<li>bind     - (<em>object</em>, optional) The object to use as 'this' within the function. For more information see <a href="function.html#Function:bind">Function:bind</a>.</li>
</ol>
<h4>Argument: fn</h4>

<h5>Syntax:</h5>

<pre class="javascript">fn<span class="br0">(</span><span class="kw1">item</span>, index, object<span class="br0">)</span>
</pre>

<h5>Arguments:</h5>

<ol>
<li>item   - (<em>mixed</em>) The current item in the array.</li>
<li>index  - (<em>number</em>) The current item's index in the array. In the case of an object, it is passed the key of that item rather than the index.</li>
<li>object - (<em>mixed</em>) The actual array/object.</li>
</ol>
<h3>Example:</h3>

<pre class="javascript">Array.<span class="me1">each</span><span class="br0">(</span><span class="br0">[</span><span class="st0">'Sun'</span>, <span class="st0">'Mon'</span>, <span class="st0">'Tue'</span><span class="br0">]</span>, <span class="kw2">function</span><span class="br0">(</span>day, index<span class="br0">)</span><span class="br0">{</span>
    <span class="kw3">alert</span><span class="br0">(</span><span class="st0">'name:'</span> + day + <span class="st0">', index: '</span> + index<span class="br0">)</span>;
<span class="br0">}</span><span class="br0">)</span>; <span class="co1">// alerts 'name: Sun, index: 0', 'name: Mon, index: 1', etc.</span>
</pre>

<h3>See Also:</h3>

<ul>
<li><a href="#Array:each">Array:each</a></li>
</ul>
<h3>Notes:</h3>

<p>This is an array-specific equivalent of <em>$each</em> from MooTools 1.2.</p>

<h2 id="Array:Array-clone"><a href="#Array:Array-clone">Function: Array.clone</a></h2>

<p class="description">Returns a copy of the passed array.</p>

<h3>Syntax:</h3>

<pre class="javascript"><span class="kw2">var</span> clone = Array.<span class="me1">clone</span><span class="br0">(</span>myArray<span class="br0">)</span>;
</pre>

<h3>Arguments:</h3>

<ol>
<li>myArray  - (<em>array</em>) The array you wish to copy.</li>
</ol>
<h3>Returns:</h3>

<ul>
<li>(<em>array</em>) a copy of the passed array.</li>
</ul>
<h3>Example:</h3>

<pre class="javascript"><span class="kw2">var</span> myArray = <span class="br0">[</span><span class="st0">'red'</span>, <span class="st0">'blue'</span>, <span class="st0">'green'</span><span class="br0">]</span>;
<span class="kw2">var</span> otherArray = Array.<span class="me1">clone</span><span class="br0">(</span>myArray<span class="br0">)</span>;
&nbsp;
<span class="kw2">var</span> myArray<span class="br0">[</span><span class="nu0">0</span><span class="br0">]</span> = <span class="st0">'yellow'</span>;
&nbsp;
<span class="kw3">alert</span><span class="br0">(</span>myArray<span class="br0">[</span><span class="nu0">0</span><span class="br0">]</span><span class="br0">)</span>;      <span class="co1">// alerts 'yellow'</span>
<span class="kw3">alert</span><span class="br0">(</span>otherArray<span class="br0">[</span><span class="nu0">0</span><span class="br0">]</span><span class="br0">)</span>    <span class="co1">// alerts 'red'</span>
</pre>

<h3>Notes:</h3>

<p>This is an array-specific equivalent of <em>$unlink</em> from MooTools 1.2.</p>

<h2 id="Array:Array-from"><a href="#Array:Array-from">Function: Array.from</a></h2>

<p class="description">Converts the argument passed in to an array if it is defined and not already an array.</p>

<h3>Syntax:</h3>

<pre class="javascript"><span class="kw2">var</span> splatted = Array.<span class="me1">from</span><span class="br0">(</span>obj<span class="br0">)</span>;
</pre>

<h3>Arguments:</h3>

<ol>
<li>obj - (<em>mixed</em>) Any type of variable.</li>
</ol>
<h3>Returns:</h3>

<ul>
<li>(<em>array</em>) If the variable passed in is an array, returns the array. Otherwise, returns an array with the only element being the variable passed in.</li>
</ul>
<h3>Example:</h3>

<pre class="javascript">Array.<span class="me1">from</span><span class="br0">(</span><span class="st0">'hello'</span><span class="br0">)</span>; <span class="co1">// returns ['hello'].</span>
Array.<span class="me1">from</span><span class="br0">(</span><span class="br0">[</span><span class="st0">'a'</span>, <span class="st0">'b'</span>, <span class="st0">'c'</span><span class="br0">]</span><span class="br0">)</span>; <span class="co1">// returns ['a', 'b', 'c'].</span>
</pre>

<h3>Notes:</h3>

<p>This is equivalent to <em>$splat</em> from MooTools 1.2, with the exception of Array-like Objects such as NodeList or FileList which <code>Array.from</code> does transform in
Arrays and <code>$splat</code> not.</p>

<h2 id="Array:each"><a href="#Array:each">Array method: each</a></h2>

<p class="description">Calls a function for each element in the array.</p>

<h3>Syntax:</h3>

<pre class="javascript">myArray.<span class="me1">each</span><span class="br0">(</span>fn<span class="br0">[</span>, bind<span class="br0">]</span><span class="br0">)</span>;
</pre>

<h3>Arguments:</h3>

<ol>
<li>fn   - (<em>function</em>) The function which should be executed on each item in the array. This function is passed the item and its index in the array.</li>
<li>bind - (<em>object</em>, optional) The object to be used as 'this' in the function. For more information see <a href="function.html#Function:bind">Function:bind</a>.</li>
</ol>
<h4>Argument: fn</h4>

<h5>Syntax</h5>

<pre class="javascript">fn<span class="br0">(</span><span class="kw1">item</span>, index, array<span class="br0">)</span>
</pre>

<h5>Arguments:</h5>

<ol>
<li>item   - (<em>mixed</em>) The current item in the array.</li>
<li>index  - (<em>number</em>) The current item's index in the array.</li>
<li>array  - (<em>array</em>) The actual array.</li>
</ol>
<h3>Examples:</h3>

<pre class="javascript"><span class="co1">//Alerts "0 = apple", "1 = banana", and so on:</span>
<span class="br0">[</span><span class="st0">'apple'</span>, <span class="st0">'banana'</span>, <span class="st0">'lemon'</span><span class="br0">]</span>.<span class="me1">each</span><span class="br0">(</span><span class="kw2">function</span><span class="br0">(</span><span class="kw1">item</span>, index<span class="br0">)</span><span class="br0">{</span>
    <span class="kw3">alert</span><span class="br0">(</span>index + <span class="st0">" = "</span> + <span class="kw1">item</span><span class="br0">)</span>;
<span class="br0">}</span><span class="br0">)</span>; <span class="co1">//The optional second argument for binding isn't used here.</span>
</pre>

<h3>See Also:</h3>

<ul>
<li><a href="#Array:Array-each">Array.each</a></li>
<li><a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array/forEach">MDC Array:forEach</a></li>
</ul>
<h3>Notes:</h3>

<ul>
<li>This method is only available for browsers without native <a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array/forEach">MDC Array:forEach</a> support.</li>
</ul>
<h2 id="Array:invoke"><a href="#Array:invoke">Array method: invoke</a></h2>

<p class="description">Returns an array with the named method applied to the array's contents.</p>

<h3>Syntax:</h3>

<pre class="javascript"><span class="kw2">var</span> arr = myArray.<span class="me1">invoke</span><span class="br0">(</span>method<span class="br0">[</span>, arg, arg, arg ...<span class="br0">]</span><span class="br0">)</span>
</pre>

<h3>Arguments:</h3>

<ol>
<li>method - (<em>string</em>) The method to apply to each item in the array.</li>
<li>arg - (<em>mixed</em>) Any number of arguments to pass to the named method.</li>
</ol>
<h3>Returns:</h3>

<ul>
<li>(<em>array</em>) A new array containing the results of the applied method.</li>
</ul>
<h3>Example:</h3>

<pre class="javascript"><span class="kw2">var</span> foo = <span class="br0">[</span><span class="nu0">4</span>, <span class="nu0">8</span>, <span class="nu0">15</span>, <span class="nu0">16</span>, <span class="nu0">23</span>, <span class="nu0">42</span><span class="br0">]</span>;
<span class="kw2">var</span> bar = foo.<span class="me1">invoke</span><span class="br0">(</span><span class="st0">'limit'</span>, <span class="nu0">10</span>, <span class="nu0">30</span><span class="br0">)</span>;  <span class="co1">//bar is now [10, 10, 15, 16, 23, 30]</span>
</pre>

<h3>Notes:</h3>

<p>The method that is invoked is a method of each of the items.
If the method does not exist, then an error will be thrown. For example:</p>

<pre class="javascript"><span class="br0">[</span><span class="nu0">0</span>, <span class="kw2">false</span>, <span class="st0">'string'</span><span class="br0">]</span>.<span class="me1">invoke</span><span class="br0">(</span><span class="st0">'limit'</span>, <span class="nu0">0</span>, <span class="nu0">10</span><span class="br0">)</span>; <span class="co1">// throws an error!</span>
</pre>

<h2 id="Array:every"><a href="#Array:every">Array method: every</a></h2>

<p class="description">Returns true if every element in the array satisfies the provided testing function.
This method is provided only for browsers without native <a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array/every">Array:every</a> support.</p>

<h3>Syntax:</h3>

<pre class="javascript"><span class="kw2">var</span> allPassed = myArray.<span class="me1">every</span><span class="br0">(</span>fn<span class="br0">[</span>, bind<span class="br0">]</span><span class="br0">)</span>;
</pre>

<h3>Arguments:</h3>

<ol>
<li>fn   - (<em>function</em>) The function to test for each element.</li>
<li>bind - (<em>object</em>, optional) The object to use as 'this' in the function. For more information see <a href="function.html#Function:bind">Function:bind</a>.</li>
</ol>
<h4>Argument: fn</h4>

<h5>Syntax:</h5>

<pre class="javascript">fn<span class="br0">(</span><span class="kw1">item</span>, index, array<span class="br0">)</span>
</pre>

<h5>Arguments:</h5>

<ol>
<li>item   - (<em>mixed</em>) The current item in the array.</li>
<li>index  - (<em>number</em>) The current item's index in the array.</li>
<li>array  - (<em>array</em>) The actual array.</li>
</ol>
<h3>Returns:</h3>

<ul>
<li>(<em>boolean</em>) If every element in the array satisfies the provided testing function, returns true. Otherwise, returns false.</li>
</ul>
<h3>Examples:</h3>

<pre class="javascript"><span class="kw2">var</span> areAllBigEnough = <span class="br0">[</span><span class="nu0">10</span>, <span class="nu0">4</span>, <span class="nu0">25</span>, <span class="nu0">100</span><span class="br0">]</span>.<span class="me1">every</span><span class="br0">(</span><span class="kw2">function</span><span class="br0">(</span><span class="kw1">item</span>, index<span class="br0">)</span><span class="br0">{</span>
    <span class="kw1">return</span> <span class="kw1">item</span> &gt; <span class="nu0">20</span>;
<span class="br0">}</span><span class="br0">)</span>; <span class="co1">// areAllBigEnough = false</span>
</pre>

<h3>See Also:</h3>

<ul>
<li><a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array/every">MDC Array:every</a></li>
</ul>
<h2 id="Array:filter"><a href="#Array:filter">Array method: filter</a></h2>

<p class="description">Creates a new array with all of the elements of the array for which the provided filtering function returns true.
This method is provided only for browsers without native <a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array/filter">Array:filter</a> support.</p>

<h3>Syntax:</h3>

<pre class="javascript"><span class="kw2">var</span> filteredArray = myArray.<span class="me1">filter</span><span class="br0">(</span>fn<span class="br0">[</span>, bind<span class="br0">]</span><span class="br0">)</span>;
</pre>

<h3>Arguments:</h3>

<ol>
<li>fn   - (<em>function</em>) The function to test each element of the array. This function is passed the item and its index in the array.</li>
<li>bind - (<em>object</em>, optional) The object to use as 'this' in the function. For more information see <a href="function.html#Function:bind">Function:bind</a>.</li>
</ol>
<h4>Argument: fn</h4>

<h5>Syntax:</h5>

<pre class="javascript">fn<span class="br0">(</span><span class="kw1">item</span>, index, array<span class="br0">)</span>
</pre>

<h5>Arguments:</h5>

<ol>
<li>item   - (<em>mixed</em>) The current item in the array.</li>
<li>index  - (<em>number</em>) The current item's index in the array.</li>
<li>array  - (<em>array</em>) The actual array.</li>
</ol>
<h3>Returns:</h3>

<ul>
<li>(<em>array</em>) The new filtered array.</li>
</ul>
<h3>Examples:</h3>

<pre class="javascript"><span class="kw2">var</span> biggerThanTwenty = <span class="br0">[</span><span class="nu0">10</span>, <span class="nu0">3</span>, <span class="nu0">25</span>, <span class="nu0">100</span><span class="br0">]</span>.<span class="me1">filter</span><span class="br0">(</span><span class="kw2">function</span><span class="br0">(</span><span class="kw1">item</span>, index<span class="br0">)</span><span class="br0">{</span>
    <span class="kw1">return</span> <span class="kw1">item</span> &gt; <span class="nu0">20</span>;
<span class="br0">}</span><span class="br0">)</span>; <span class="co1">// biggerThanTwenty = [25, 100]</span>
</pre>

<h3>See Also:</h3>

<ul>
<li><a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array/filter">MDC Array:filter</a></li>
</ul>
<h2 id="Array:clean"><a href="#Array:clean">Array method: clean</a></h2>

<p class="description">Creates a new array with all of the elements of the array which are defined (i.e. not null or undefined).</p>

<h3>Syntax:</h3>

<pre class="javascript"><span class="kw2">var</span> cleanedArray = myArray.<span class="me1">clean</span><span class="br0">(</span><span class="br0">)</span>;
</pre>

<h3>Returns:</h3>

<ul>
<li>(<em>array</em>) The new filtered array.</li>
</ul>
<h3>Examples:</h3>

<pre class="javascript"><span class="kw2">var</span> myArray = <span class="br0">[</span><span class="kw2">null</span>, <span class="nu0">1</span>, <span class="nu0">0</span>, <span class="kw2">true</span>, <span class="kw2">false</span>, <span class="st0">'foo'</span>, undefined, <span class="st0">''</span><span class="br0">]</span>;
myArray.<span class="me1">clean</span><span class="br0">(</span><span class="br0">)</span> <span class="co1">// returns [1, 0, true, false, 'foo', '']</span>
</pre>

<h2 id="Array:indexOf"><a href="#Array:indexOf">Array method: indexOf</a></h2>

<p class="description">Returns the index of the first element within the array equal to the specified value, or -1 if the value is not found.
This method is provided only for browsers without native <a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array/indexOf">Array:indexOf</a> support.</p>

<h3>Syntax:</h3>

<pre class="javascript"><span class="kw2">var</span> index = myArray.<span class="me1">indexOf</span><span class="br0">(</span><span class="kw1">item</span><span class="br0">[</span>, from<span class="br0">]</span><span class="br0">)</span>;
</pre>

<h3>Returns:</h3>

<ul>
<li>(<em>number</em>) The index of the first element within the array equal to the specified value. If not found, returns -1.</li>
</ul>
<h3>Arguments:</h3>

<ol>
<li>item - (<em>object</em>) The item to search for in the array.</li>
<li>from - (<em>number</em>, optional: defaults to 0) The index of the array at which to begin the search.</li>
</ol>
<h3>Examples:</h3>

<pre class="javascript"><span class="br0">[</span><span class="st0">'apple'</span>, <span class="st0">'lemon'</span>, <span class="st0">'banana'</span><span class="br0">]</span>.<span class="me1">indexOf</span><span class="br0">(</span><span class="st0">'lemon'</span><span class="br0">)</span>; <span class="co1">// returns 1</span>
<span class="br0">[</span><span class="st0">'apple'</span>, <span class="st0">'lemon'</span><span class="br0">]</span>.<span class="me1">indexOf</span><span class="br0">(</span><span class="st0">'banana'</span><span class="br0">)</span>; <span class="co1">// returns -1</span>
</pre>

<h3>See Also:</h3>

<ul>
<li><a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array/indexOf">MDC Array:indexOf</a></li>
</ul>
<h2 id="Array:map"><a href="#Array:map">Array method: map</a></h2>

<p class="description">Creates a new array with the results of calling a provided function on every element in the array.
This method is provided only for browsers without native <a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array/map">Array:map</a> support.</p>

<h3>Syntax:</h3>

<pre class="javascript"><span class="kw2">var</span> mappedArray = myArray.<span class="me1">map</span><span class="br0">(</span>fn<span class="br0">[</span>, bind<span class="br0">]</span><span class="br0">)</span>;
</pre>

<h3>Arguments:</h3>

<ol>
<li>fn   - (<em>function</em>) The function to produce an element of the new Array from an element of the current one.</li>
<li>bind - (<em>object</em>, optional) The object to use as 'this' in the function. For more information see <a href="function.html#Function:bind">Function:bind</a>.</li>
</ol>
<h4>Argument: fn</h4>

<h5>Syntax:</h5>

<pre class="javascript">fn<span class="br0">(</span><span class="kw1">item</span>, index, array<span class="br0">)</span>
</pre>

<h5>Arguments:</h5>

<ol>
<li>item   - (<em>mixed</em>) The current item in the array.</li>
<li>index  - (<em>number</em>) The current item's index in the array.</li>
<li>array  - (<em>array</em>) The actual array.</li>
</ol>
<h3>Returns:</h3>

<ul>
<li>(<em>array</em>) The new mapped array.</li>
</ul>
<h3>Examples:</h3>

<pre class="javascript"><span class="kw2">var</span> timesTwo = <span class="br0">[</span><span class="nu0">1</span>, <span class="nu0">2</span>, <span class="nu0">3</span><span class="br0">]</span>.<span class="me1">map</span><span class="br0">(</span><span class="kw2">function</span><span class="br0">(</span><span class="kw1">item</span>, index<span class="br0">)</span><span class="br0">{</span>
    <span class="kw1">return</span> <span class="kw1">item</span> * <span class="nu0">2</span>;
<span class="br0">}</span><span class="br0">)</span>; <span class="co1">//timesTwo = [2, 4, 6];</span>
</pre>

<h3>See Also:</h3>

<ul>
<li><a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array/map">MDC Array:map</a></li>
</ul>
<h2 id="Array:some"><a href="#Array:some">Array method: some</a></h2>

<p class="description">Returns true if at least one element in the array satisfies the provided testing function.
This method is provided only for browsers without native <a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array/some">Array:some</a> support.</p>

<h3>Syntax:</h3>

<pre class="javascript"><span class="kw2">var</span> somePassed = myArray.<span class="me1">some</span><span class="br0">(</span>fn<span class="br0">[</span>, bind<span class="br0">]</span><span class="br0">)</span>;
</pre>

<h3>Returns:</h3>

<ul>
<li>(<em>boolean</em>) If at least one element in the array satisfies the provided testing function returns true. Otherwise, returns false.</li>
</ul>
<h3>Arguments:</h3>

<ol>
<li>fn   - (<em>function</em>) The function to test for each element. This function is passed the item and its index in the array.</li>
<li>bind - (<em>object</em>, optional) The object to use as 'this' in the function. For more information see <a href="function.html#Function:bind">Function:bind</a>.</li>
</ol>
<h4>Argument: fn</h4>

<h5>Syntax:</h5>

<pre class="javascript">fn<span class="br0">(</span><span class="kw1">item</span>, index, array<span class="br0">)</span>
</pre>

<h5>Arguments:</h5>

<ol>
<li>item   - (<em>mixed</em>) The current item in the array.</li>
<li>index  - (<em>number</em>) The current item's index in the array.</li>
<li>array  - (<em>array</em>) The actual array.</li>
</ol>
<h3>Examples:</h3>

<pre class="javascript"><span class="kw2">var</span> isAnyBigEnough = <span class="br0">[</span><span class="nu0">10</span>, <span class="nu0">4</span>, <span class="nu0">25</span>, <span class="nu0">100</span><span class="br0">]</span>.<span class="me1">some</span><span class="br0">(</span><span class="kw2">function</span><span class="br0">(</span><span class="kw1">item</span>, index<span class="br0">)</span><span class="br0">{</span>
    <span class="kw1">return</span> <span class="kw1">item</span> &gt; <span class="nu0">20</span>;
<span class="br0">}</span><span class="br0">)</span>; <span class="co1">// isAnyBigEnough = true</span>
</pre>

<h3>See Also:</h3>

<ul>
<li><a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array/some">MDC Array:some</a></li>
</ul>
<h2 id="Array:associate"><a href="#Array:associate">Array method: associate</a></h2>

<p class="description">Creates an object with key-value pairs based on the array of keywords passed in and the current content of the array.</p>

<h3>Syntax:</h3>

<pre class="javascript"><span class="kw2">var</span> associated = myArray.<span class="me1">associate</span><span class="br0">(</span>obj<span class="br0">)</span>;
</pre>

<h3>Arguments:</h3>

<ol>
<li>obj - (<em>array</em>) Its items will be used as the keys of the object that will be created.</li>
</ol>
<h3>Returns:</h3>

<ul>
<li>(<em>object</em>) The new associated object.</li>
</ul>
<h3>Examples:</h3>

<pre class="javascript"><span class="kw2">var</span> animals = <span class="br0">[</span><span class="st0">'Cow'</span>, <span class="st0">'Pig'</span>, <span class="st0">'Dog'</span>, <span class="st0">'Cat'</span><span class="br0">]</span>;
<span class="kw2">var</span> sounds = <span class="br0">[</span><span class="st0">'Moo'</span>, <span class="st0">'Oink'</span>, <span class="st0">'Woof'</span>, <span class="st0">'Miao'</span><span class="br0">]</span>;
sounds.<span class="me1">associate</span><span class="br0">(</span>animals<span class="br0">)</span>;
<span class="co1">// returns {'Cow': 'Moo', 'Pig': 'Oink', 'Dog': 'Woof', 'Cat': 'Miao'}</span>
</pre>

<h2 id="Array:link"><a href="#Array:link">Array method: link</a></h2>

<p class="description">Accepts an object of key / function pairs to assign values.</p>

<h3>Syntax:</h3>

<pre class="javascript"><span class="kw2">var</span> result = myArray.<span class="me1">link</span><span class="br0">(</span>object<span class="br0">)</span>;
</pre>

<h3>Arguments:</h3>

<ol>
<li>object - (<em>object</em>)  An object containing key / function pairs must be passed to be used as a template for associating values with the different keys.</li>
</ol>
<h3>Returns:</h3>

<ul>
<li>(<em>object</em>) The new associated object.</li>
</ul>
<h3>Examples:</h3>

<pre class="javascript"><span class="kw2">var</span> el = document.<span class="me1">createElement</span><span class="br0">(</span><span class="st0">'div'</span><span class="br0">)</span>;
<span class="kw2">var</span> arr2 = <span class="br0">[</span><span class="nu0">100</span>, <span class="st0">'Hello'</span>, <span class="br0">{</span>foo: <span class="st0">'bar'</span><span class="br0">}</span>, el, <span class="kw2">false</span><span class="br0">]</span>;
arr2.<span class="me1">link</span><span class="br0">(</span><span class="br0">{</span>
    myNumber: Type.<span class="me1">isNumber</span>,
    myElement: Type.<span class="me1">isElement</span>,
    myObject: Type.<span class="me1">isObject</span>,
    myString: Type.<span class="me1">isString</span>,
    myBoolean: <span class="kw2">function</span><span class="br0">(</span>obj<span class="br0">)</span><span class="br0">{</span> <span class="kw1">return</span> obj != <span class="kw2">null</span>; <span class="br0">}</span>
<span class="br0">}</span><span class="br0">)</span>;
<span class="co1">// returns {myNumber: 100, myElement: el, myObject: {foo: 'bar'}, myString: 'Hello', myBoolean: false}</span>
</pre>

<h2 id="Array:contains"><a href="#Array:contains">Array method: contains</a></h2>

<p class="description">Tests an array for the presence of an item.</p>

<h3>Syntax:</h3>

<pre class="javascript"><span class="kw2">var</span> inArray = myArray.<span class="me1">contains</span><span class="br0">(</span><span class="kw1">item</span><span class="br0">[</span>, from<span class="br0">]</span><span class="br0">)</span>;
</pre>

<h3>Arguments:</h3>

<ol>
<li>item - (<em>object</em>) The item to search for in the array.</li>
<li>from - (<em>number</em>, optional: defaults to 0) The index of the array at which to begin the search.</li>
</ol>
<h3>Returns:</h3>

<ul>
<li>(<em>boolean</em>) If the array contains the item specified, returns true. Otherwise, returns false.</li>
</ul>
<h3>Examples:</h3>

<pre class="javascript"><span class="br0">[</span><span class="st0">'a'</span>, <span class="st0">'b'</span>, <span class="st0">'c'</span><span class="br0">]</span>.<span class="me1">contains</span><span class="br0">(</span><span class="st0">'a'</span><span class="br0">)</span>; <span class="co1">// returns true</span>
<span class="br0">[</span><span class="st0">'a'</span>, <span class="st0">'b'</span>, <span class="st0">'c'</span><span class="br0">]</span>.<span class="me1">contains</span><span class="br0">(</span><span class="st0">'d'</span><span class="br0">)</span>; <span class="co1">// returns false</span>
</pre>

<h3>See Also:</h3>

<ul>
<li><a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array/indexOf">MDC Array:indexOf</a></li>
</ul>
<h2 id="Array:append"><a href="#Array:append">Array method: append</a></h2>

<p class="description">Appends the passed array to the end of the current array.</p>

<h3>Syntax:</h3>

<pre class="javascript"><span class="kw2">var</span> myArray = myArray.<span class="me1">append</span><span class="br0">(</span>otherArray<span class="br0">)</span>;
</pre>

<h3>Arguments:</h3>

<ol>
<li>otherArray - (<em>array</em>) The array containing values you wish to append.</li>
</ol>
<h3>Returns:</h3>

<ul>
<li>(<em>array</em>) The original array including the new values.</li>
</ul>
<h3>Examples:</h3>

<pre class="javascript"><span class="kw2">var</span> myOtherArray = <span class="br0">[</span><span class="st0">'green'</span>, <span class="st0">'yellow'</span><span class="br0">]</span>;
<span class="br0">[</span><span class="st0">'red'</span>, <span class="st0">'blue'</span><span class="br0">]</span>.<span class="me1">append</span><span class="br0">(</span>myOtherArray<span class="br0">)</span>; <span class="co1">// returns ['red', 'blue', 'green', 'yellow'];</span>
myOtheArray; <span class="co1">// is now ['red', 'blue', 'green', 'yellow'];</span>
&nbsp;
<span class="br0">[</span><span class="nu0">0</span>, <span class="nu0">1</span>, <span class="nu0">2</span><span class="br0">]</span>.<span class="me1">append</span><span class="br0">(</span><span class="br0">[</span><span class="nu0">3</span>, <span class="br0">[</span><span class="nu0">4</span><span class="br0">]</span><span class="br0">]</span><span class="br0">)</span>; <span class="co1">// [0, 1, 2, 3, [4]]</span>
</pre>

<h3>Notes:</h3>

<p>This is an array-specific equivalent of <em>$extend</em> from MooTools 1.2.</p>

<h2 id="Array:getLast"><a href="#Array:getLast">Array method: getLast</a></h2>

<p class="description">Returns the last item from the array.</p>

<h3>Syntax:</h3>

<pre class="javascript">myArray.<span class="me1">getLast</span><span class="br0">(</span><span class="br0">)</span>;
</pre>

<h3>Returns:</h3>

<ul>
<li>(<em>mixed</em>) The last item in this array.</li>
<li>(<em>null</em>) If this array is empty, returns null.</li>
</ul>
<h3>Examples:</h3>

<pre class="javascript"><span class="br0">[</span><span class="st0">'Cow'</span>, <span class="st0">'Pig'</span>, <span class="st0">'Dog'</span>, <span class="st0">'Cat'</span><span class="br0">]</span>.<span class="me1">getLast</span><span class="br0">(</span><span class="br0">)</span>; <span class="co1">// returns 'Cat'</span>
</pre>

<h2 id="Array:getRandom"><a href="#Array:getRandom">Array method: getRandom</a></h2>

<p class="description">Returns a random item from the array.</p>

<h3>Syntax:</h3>

<pre class="javascript">myArray.<span class="me1">getRandom</span><span class="br0">(</span><span class="br0">)</span>;
</pre>

<h3>Returns:</h3>

<ul>
<li>(<em>mixed</em>) A random item from this array. If this array is empty, returns null.</li>
</ul>
<h3>Examples:</h3>

<pre class="javascript"><span class="br0">[</span><span class="st0">'Cow'</span>, <span class="st0">'Pig'</span>, <span class="st0">'Dog'</span>, <span class="st0">'Cat'</span><span class="br0">]</span>.<span class="me1">getRandom</span><span class="br0">(</span><span class="br0">)</span>; <span class="co1">// returns one of the items</span>
</pre>

<h2 id="Array:include"><a href="#Array:include">Array method: include</a></h2>

<p class="description">Pushes the passed element into the array if it's not already present (case and type sensitive).</p>

<h3>Syntax:</h3>

<pre class="javascript">myArray.<span class="me1">include</span><span class="br0">(</span><span class="kw1">item</span><span class="br0">)</span>;
</pre>

<h3>Arguments:</h3>

<ol>
<li>item - (<em>object</em>) The item that should be added to this array.</li>
</ol>
<h3>Returns:</h3>

<ul>
<li>(<em>array</em>) This array with the new item included.</li>
</ul>
<h3>Examples:</h3>

<pre class="javascript"><span class="br0">[</span><span class="st0">'Cow'</span>, <span class="st0">'Pig'</span>, <span class="st0">'Dog'</span><span class="br0">]</span>.<span class="me1">include</span><span class="br0">(</span><span class="st0">'Cat'</span><span class="br0">)</span>; <span class="co1">// returns ['Cow', 'Pig', 'Dog', 'Cat']</span>
<span class="br0">[</span><span class="st0">'Cow'</span>, <span class="st0">'Pig'</span>, <span class="st0">'Dog'</span><span class="br0">]</span>.<span class="me1">include</span><span class="br0">(</span><span class="st0">'Dog'</span><span class="br0">)</span>; <span class="co1">// returns ['Cow', 'Pig', 'Dog']</span>
</pre>

<h3>Notes:</h3>

<p>If you want to push the passed element even if it's already present, use
the vanilla javascript:</p>

<pre class="javascript">myArray.<span class="me1">push</span><span class="br0">(</span><span class="kw1">item</span><span class="br0">)</span>;
</pre>

<h2 id="Array:combine"><a href="#Array:combine">Array method: combine</a></h2>

<p class="description">Combines an array with all the items of another. Does not allow duplicates and is case and type sensitive.</p>

<h3>Syntax:</h3>

<pre class="javascript">myArray.<span class="me1">combine</span><span class="br0">(</span>array<span class="br0">)</span>;
</pre>

<h3>Arguments:</h3>

<ol>
<li>array - (<em>array</em>) The array whose items should be combined into this array.</li>
</ol>
<h3>Returns:</h3>

<ul>
<li>(<em>array</em>) This array combined with the new items.</li>
</ul>
<h3>Examples:</h3>

<pre class="javascript"><span class="kw2">var</span> animals = <span class="br0">[</span><span class="st0">'Cow'</span>, <span class="st0">'Pig'</span>, <span class="st0">'Dog'</span><span class="br0">]</span>;
animals.<span class="me1">combine</span><span class="br0">(</span><span class="br0">[</span><span class="st0">'Cat'</span>, <span class="st0">'Dog'</span><span class="br0">]</span><span class="br0">)</span>; <span class="co1">//animals = ['Cow', 'Pig', 'Dog', 'Cat'];</span>
</pre>

<h2 id="Array:erase"><a href="#Array:erase">Array method: erase</a></h2>

<p class="description">Removes all occurrences of an item from the array.</p>

<h3>Syntax:</h3>

<pre class="javascript">myArray.<span class="me1">erase</span><span class="br0">(</span><span class="kw1">item</span><span class="br0">)</span>;
</pre>

<h3>Arguments:</h3>

<ol>
<li>item - (<em>object</em>) The item to search for in the array.</li>
</ol>
<h3>Returns:</h3>

<ul>
<li>(<em>array</em>) This array with all occurrences of the item removed.</li>
</ul>
<h3>Examples:</h3>

<pre class="javascript"><span class="br0">[</span><span class="st0">'Cow'</span>, <span class="st0">'Pig'</span>, <span class="st0">'Dog'</span>, <span class="st0">'Cat'</span>, <span class="st0">'Dog'</span><span class="br0">]</span>.<span class="me1">erase</span><span class="br0">(</span><span class="st0">'Dog'</span><span class="br0">)</span> <span class="co1">// returns ['Cow', 'Pig', 'Cat']</span>
<span class="br0">[</span><span class="st0">'Cow'</span>, <span class="st0">'Pig'</span>, <span class="st0">'Dog'</span><span class="br0">]</span>.<span class="me1">erase</span><span class="br0">(</span><span class="st0">'Cat'</span><span class="br0">)</span> <span class="co1">// returns ['Cow', 'Pig', 'Dog']</span>
</pre>

<h2 id="Array:empty"><a href="#Array:empty">Array method: empty</a></h2>

<p class="description">Empties an array.</p>

<h3>Syntax:</h3>

<pre class="javascript">myArray.<span class="me1">empty</span><span class="br0">(</span><span class="br0">)</span>;
</pre>

<h3>Returns:</h3>

<ul>
<li>(<em>array</em>) This array, emptied.</li>
</ul>
<h3>Examples:</h3>

<pre class="javascript"><span class="kw2">var</span> myArray = <span class="br0">[</span><span class="st0">'old'</span>, <span class="st0">'data'</span><span class="br0">]</span>;
myArray.<span class="me1">empty</span><span class="br0">(</span><span class="br0">)</span>; <span class="co1">//myArray is now []</span>
</pre>

<h2 id="Array:flatten"><a href="#Array:flatten">Array method: flatten</a></h2>

<p class="description">Flattens a multidimensional array into a single array.</p>

<h3>Syntax:</h3>

<pre class="javascript">myArray.<span class="me1">flatten</span><span class="br0">(</span><span class="br0">)</span>;
</pre>

<h3>Returns:</h3>

<ul>
<li>(<em>array</em>) A new flat array.</li>
</ul>
<h3>Examples:</h3>

<pre class="javascript"><span class="kw2">var</span> myArray = <span class="br0">[</span><span class="nu0">1</span>,<span class="nu0">2</span>,<span class="nu0">3</span>,<span class="br0">[</span><span class="nu0">4</span>,<span class="nu0">5</span>, <span class="br0">[</span><span class="nu0">6</span>,<span class="nu0">7</span><span class="br0">]</span><span class="br0">]</span>, <span class="br0">[</span><span class="br0">[</span><span class="br0">[</span><span class="nu0">8</span><span class="br0">]</span><span class="br0">]</span><span class="br0">]</span><span class="br0">]</span>;
<span class="kw2">var</span> newArray = myArray.<span class="me1">flatten</span><span class="br0">(</span><span class="br0">)</span>; <span class="co1">//newArray is [1,2,3,4,5,6,7,8]</span>
</pre>

<h2 id="Array:pick"><a href="#Array:pick">Array method: pick</a></h2>

<p class="description">Returns the first defined value of the array passed in, or null.</p>

<h3>Syntax:</h3>

<pre class="javascript"><span class="kw2">var</span> picked = <span class="br0">[</span>var1, var2, var3<span class="br0">]</span>.<span class="me1">pick</span><span class="br0">(</span><span class="br0">)</span>;
</pre>

<h3>Returns:</h3>

<ul>
<li>(<em>mixed</em>) The first variable that is defined.</li>
<li>(<em>null</em>) If all variables passed in are <code>null</code> or <code>undefined</code>, returns <code>null</code>.</li>
</ul>
<h3>Example:</h3>

<pre class="javascript"><span class="kw2">function</span> say<span class="br0">(</span>infoMessage, errorMessage<span class="br0">)</span><span class="br0">{</span>
    <span class="kw3">alert</span><span class="br0">(</span><span class="br0">[</span>errorMessage, infoMessage, <span class="st0">'There was no message supplied.'</span><span class="br0">]</span>.<span class="me1">pick</span><span class="br0">(</span><span class="br0">)</span><span class="br0">)</span>;
&nbsp;
    <span class="co1">//or more MooTools 1.2 style using Generics</span>
    Array.<span class="me1">pick</span><span class="br0">(</span><span class="br0">[</span>errorMessage, infoMessage, <span class="st0">'There was no message supplied.'</span><span class="br0">]</span><span class="br0">)</span>;
&nbsp;
<span class="br0">}</span>
say<span class="br0">(</span><span class="br0">)</span>; <span class="co1">// alerts 'There was no message supplied.'</span>
say<span class="br0">(</span><span class="st0">'This is an info message.'</span><span class="br0">)</span>; <span class="co1">// alerts 'This is an info message.'</span>
say<span class="br0">(</span><span class="st0">'This message will be ignored.'</span>, <span class="st0">'This is the error message.'</span><span class="br0">)</span>; <span class="co1">// alerts 'This is the error message.'</span>
</pre>

<h3>Notes:</h3>

<p>This is equivalent to <em>$pick</em> from MooTools 1.2.</p>

<h2 id="Array:hexToRgb"><a href="#Array:hexToRgb">Array method: hexToRgb</a></h2>

<p class="description">Converts an hexadecimal color value to RGB. Input array must be the following hexadecimal color format.
['FF', 'FF', 'FF']</p>

<h3>Syntax:</h3>

<pre class="javascript">myArray.<span class="me1">hexToRgb</span><span class="br0">(</span><span class="br0">[</span>array<span class="br0">]</span><span class="br0">)</span>;
</pre>

<h3>Arguments:</h3>

<ol>
<li>array - (<em>boolean</em>, optional) If true is passed, will output an array (e.g. [255, 51, 0]) instead of a string (e.g. "rgb(255, 51, 0)").</li>
</ol>
<h3>Returns:</h3>

<ul>
<li>(<em>string</em>) A string representing the color in RGB.</li>
<li>(<em>array</em>) If the array flag is set, an array will be returned instead.</li>
</ul>
<h3>Examples:</h3>

<pre class="javascript"><span class="br0">[</span><span class="st0">'11'</span>, <span class="st0">'22'</span>, <span class="st0">'33'</span><span class="br0">]</span>.<span class="me1">hexToRgb</span><span class="br0">(</span><span class="br0">)</span>; <span class="co1">// returns 'rgb(17, 34, 51)'</span>
<span class="br0">[</span><span class="st0">'11'</span>, <span class="st0">'22'</span>, <span class="st0">'33'</span><span class="br0">]</span>.<span class="me1">hexToRgb</span><span class="br0">(</span><span class="kw2">true</span><span class="br0">)</span>; <span class="co1">// returns [17, 34, 51]</span>
</pre>

<h3>See Also:</h3>

<ul>
<li><a href="string.html#String:hexToRgb">String:hexToRgb</a></li>
</ul>
<h2 id="Array:rgbToHex"><a href="#Array:rgbToHex">Array method: rgbToHex</a></h2>

<p class="description">Converts an RGB color value to hexadecimal. Input array must be in one of the following RGB color formats.
[255, 255, 255], or [255, 255, 255, 1]</p>

<h3>Syntax:</h3>

<pre class="javascript">myArray.<span class="me1">rgbToHex</span><span class="br0">(</span><span class="br0">[</span>array<span class="br0">]</span><span class="br0">)</span>;
</pre>

<h3>Arguments:</h3>

<ol>
<li>array - (<em>boolean</em>, optional) If true is passed, will output an array (e.g. ['ff', '33', '00']) instead of a string (e.g. '#ff3300').</li>
</ol>
<h3>Returns:</h3>

<ul>
<li>(<em>string</em>) A string representing the color in hexadecimal, or 'transparent' string if the fourth value of rgba in the input array is 0 (rgba).</li>
<li>(<em>array</em>) If the array flag is set, an array will be returned instead.</li>
</ul>
<h3>Examples:</h3>

<pre class="javascript"><span class="br0">[</span><span class="nu0">17</span>, <span class="nu0">34</span>, <span class="nu0">51</span><span class="br0">]</span>.<span class="me1">rgbToHex</span><span class="br0">(</span><span class="br0">)</span>; <span class="co1">// returns '#112233'</span>
<span class="br0">[</span><span class="nu0">17</span>, <span class="nu0">34</span>, <span class="nu0">51</span><span class="br0">]</span>.<span class="me1">rgbToHex</span><span class="br0">(</span><span class="kw2">true</span><span class="br0">)</span>; <span class="co1">// returns ['11', '22', '33']</span>
<span class="br0">[</span><span class="nu0">17</span>, <span class="nu0">34</span>, <span class="nu0">51</span>, <span class="nu0">0</span><span class="br0">]</span>.<span class="me1">rgbToHex</span><span class="br0">(</span><span class="br0">)</span>; <span class="co1">// returns 'transparent'</span>
</pre>

<h3>See Also:</h3>

<ul>
<li><a href="string.html#String:rgbToHex">String:rgbToHex</a></li>
</ul>

    </div>
  </div>
<script type="text/javascript" src="../../../assets/mootools-core-1.3.js"></script>
<script type="text/javascript" src="../../../assets/mootools-more-smoothscroll.js"></script>
<script type="text/javascript" src="../../../assets/doc-assist.js"></script>
</body>
</html>
